<?php

/**
 * Class ApiController
 */
class OtherController extends BaseController
{

	/*
	|--------------------------------------------------------------------------
	| API控制器
	|--------------------------------------------------------------------------
	|   GetStorageDetail                仓储详情
	|   GetHarbourDetail                港口详情
	|   GetForestDetail                 林场详情
	|
	*/
    /**
     * 表单参数
     * @param $obj
     * @param $arr
     * @author  alice
     * @date    2016-1-14
     * @return bool
     */
    public function  checkProperties($obj, $arr)
    {
        if(empty($arr)) return true;
        $obj    =   (array) $obj;

        foreach($arr as $v){
            if(empty($obj[$v])){
                return false;}
        }
        return true;
    }

    public function ApiTest()
    {
        return $this->view('webview.api');
    }

    /**
     * 仓储地列表
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     */
    public function ShowStorageList()
    {
        $info = OtherService::instance()->ShowStorageList();
        return $this->view('admin.show_storage')->with('storage',$info);

    }

    /**
     * 新增仓储地
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     * @throws Exception
     */
    public function AddStorage()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                              =     new stdClass();
            $aData->storage_name                =     $this->getParam('storage_name');
            $aData->storage_address             =     $this->getParam('storage_address');
            $aData->storage_img                 =     $this->getParam('storage_img');
            $aData->quote                       =     $this->getParam('quote');
            $aData->other_fee                   =     $this->getParam('other_fee');
            $aData->introduce                   =     $this->getParam('introduce');
            $aData->video_url                   =     $this->getParam('video_url');

            #逻辑操作
            OtherService::instance()->AddStorage($aData);
            return Redirect::to('/show_storage');}else{
            return $this->view('admin.add_storage');
        }
    }

    /**
     * 修改仓储地
     * @author  alice
     * @date    2016-1-18
     * @return mixed
     */
    public function EditStorage()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                              =     new stdClass();
            $aData->storage_id                  =     $this->getParam('storage_id');
            $aData->storage_name                =     $this->getParam('storage_name');
            $aData->storage_address             =     $this->getParam('storage_address');
            $aData->storage_img                 =     $this->getParam('storage_img');
            $aData->quote                       =     $this->getParam('quote');
            $aData->other_cost                  =     $this->getParam('other_cost');
            $aData->introduce                   =     $this->getParam('introduce');

            #逻辑操作
            OtherService::instance()->EditStorage($aData);
            return Redirect::to('/show_storage');}else{
            $id =  $this->getParam('storage_id');
            $info = OtherService::instance()->ShowStorageInfo($id);
            return $this->view('admin.edit_storage')->with('storage',$info);
        }
    }

    /**
     * 林场列表
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     */
    public function ShowForestList()
    {
        $info = OtherService::instance()->ShowForestList();
        return $this->view('admin.show_forest')->with('forests',$info);

    }

    /**
     * 新增林场
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     * @throws Exception
     */
    public function AddForest()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->forest_name                =     $this->getParam('forest_name');
            $aData->country                    =     $this->getParam('country');
            $aData->resource                   =     $this->getParam('resource');
            $aData->product_cate               =     $this->getParam('product_cate');
            $aData->img                        =     $this->getParam('img');
            $aData->introduces                 =     $this->getParam('introduces');
            $aData->video_url                  =     $this->getParam('video_url');

            #逻辑操作
            OtherService::instance()->AddForest($aData);
            return Redirect::to('/show_forest');}else{
            return $this->view('admin.add_forest');
        }
    }

    /**
     * 修改林场
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     */
    public function EditForest()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->forest_id                  =     $this->getParam('forest_id');
            $aData->forest_name                =     $this->getParam('forest_name');
            $aData->country                    =     $this->getParam('country');
            $aData->product_cate               =     $this->getParam('product_cate');
            $aData->img                        =     $this->getParam('img');
            $aData->introduces                 =     $this->getParam('introduces');

            #逻辑操作
            OtherService::instance()->EditForest($aData);
            return Redirect::to('/show_forest');}else{
            $id = $this->getParam('forest_id');
            $info = OtherService::instance()->ShowForestInfo($id);
            return $this->view('admin.edit_forest')->with('forest',$info);
        }
    }

    /**
     * 港口列表
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     */
    public function ShowHarbourList()
    {
        $info = OtherService::instance()->ShowHarbourList();
        return $this->view('admin.show_harbour')->with('harbours',$info);

    }

    /**
     * 新增港口
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     * @throws Exception
     */
    public function AddHarbour()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                              = new stdClass();
            $aData->harbour_name                =     $this->getParam('harbour_name');
            $aData->city                        =     $this->getParam('city');
            $aData->introduces                  =     $this->getParam('introduces');
            $aData->quote                       =     $this->getParam('quote');
            $aData->img                         =     $this->getParam('img');
            $aData->other_cost                  =     $this->getParam('other_cost');
            $aData->video_url                   =     $this->getParam('video_url');

            #逻辑操作
            OtherService::instance()->AddHarbour($aData);
            return Redirect::to('/show_harbour');}else{
            return $this->view('admin.add_harbour');
        }
    }

    /**
     * 修改港口
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     * @throws Exception
     */
    public function EditHarbour()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                              = new stdClass();
            $aData->harbour_id                  =     $this->getParam('harbour_id');
            $aData->harbour_name                =     $this->getParam('harbour_name');
            $aData->city                        =     $this->getParam('city');
            $aData->introduces                  =     $this->getParam('introduces');
            $aData->quote                       =     $this->getParam('quote');
            $aData->img                         =     $this->getParam('img');
            $aData->other_cost                  =     $this->getParam('other_cost');

            #逻辑操作
            OtherService::instance()->EditHarbour($aData);
            return Redirect::to('/show_harbour');}else{
            $id = $this->getParam('harbour_id');
            $info = OtherService::instance()->ShowHarbourInfo($id);
            return $this->view('admin.edit_harbour')->with('harbour',$info);
        }
    }

    /**
     * 港口需求列表
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     */
    public function ShowHarbourNeedList()
    {
        $info = OtherService::instance()->ShowHarbourNeedList();
        return $this->view('admin.show_harbour_need')->with('harbours',$info);

    }

    /**
     * 新增港口需求
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     */
    public function AddHarbourNeed()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->product_name                    =     $this->getParam('harbour_name');
            $aData->number                          =     $this->getParam('number');
            $aData->spec                            =     $this->getParam('spec');
            $aData->expire_time                     =     $this->getParam('expire_time');
            $aData->certificate                     =     $this->getParam('certificate');
            $aData->introduce                       =     $this->getParam('introduce');
            $aData->contacts                        =     $this->getParam('contacts');
            $aData->mobile                          =     $this->getParam('mobile');
            #逻辑操作
            $check =  $this->checkProperties($aData,['product_name','number','spec','certificate','introduce','contacts','mobile']);
            if(!$check){
                $this->rest->error('传参为空!',ErrorCodeEnum::STATUS_ERROR,$aData);}
            OtherService::instance()->AddHarbourNeed($aData);
            $this->ShowHarbourNeedList();}else{
            return $this->view('admin.add_harbour_need');
        }
    }

    /**
     * 首页广告图展示
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     */
    public function ShowAdsList()
    {
        $info = OtherService::instance()->ShowAdsList();
        return $this->view('admin.show_ads')->with('ads',$info);

    }


    /**
     * 新增广告图
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     * @throws Exception
     */
    public function AddAds()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->ads_name                        =     $this->getParam('ads_name');
            $aData->img                             =     $this->getParam('img');
            $aData->type                            =     $this->getParam('type');
            $aData->url                             =     $this->getParam('url');
            $aData->order_by                        =     $this->getParam('order_by');

            #逻辑操作
            OtherService::instance()->AddAds($aData);
            return Redirect::to('/show_ads');}else{
            return $this->view('admin.add_ads')->with('ads_types',AdEnum::$ad_types);
        }
    }

    /**
     * 修改广告图
     * @author  alice
     * @date    2016-1-19
     * @return mixed
     */
    public function EditAds()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData = new stdClass();
            $aData->ads_id                          =     $this->getParam('ads_id');
            $aData->ads_name                        =     $this->getParam('ads_name');
            $aData->img                             =     $this->getParam('img');
            $aData->type                            =     $this->getParam('type');
            $aData->url                             =     $this->getParam('url');
            $aData->order_by                        =     $this->getParam('order_by');

            #逻辑操作
            OtherService::instance()->EditAds($aData);
            return Redirect::to('/show_ads');}else{
            $id =   $this->getParam('ads_id');
            $info = OtherService::instance()->ShowAdsInfo($id);
            return $this->view('admin.edit_ads')->with(['ads'=>$info, 'ads_types'=>AdEnum::$ad_types]);
        }
    }

    /**
     * 消息列表
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     */
    public function ShowNoticeList()
    {
        $info = OtherService::instance()->ShowNoticeList();
        return $this->view('admin.show_notice')->with('notices',$info);

    }

    /**
     * 添加消息
     * @author  alice
     * @date    2016-1-16
     * @return mixed
     * @throws Exception
     */
    public function AddNotice()
{
    if(Request::isMethod('POST'))
    {
        #收集信息
        $aData                          =     new stdClass();
        $aData->title                   =     $this->getParam('title');
        $aData->type                    =     $this->getParam('type');
        $aData->content                 =     $this->getParam('content');

        #逻辑操作
        OtherService::instance()->AddNotice($aData);
        return Redirect::to('/show_notice');}else{
        return $this->view('admin.add_notice')->with('type',NoticeEnum::$notice_types);
    }
}

    /**
     * 修改消息
     * @author  alice
     * @date    2016-1-18
     * @return mixed
     */
    public function EditNotice()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                          =     new stdClass();
            $aData->notice_id               =     $this->getParam('notice_id');
            $aData->title                   =     $this->getParam('title');
            $aData->type                    =     $this->getParam('type');
            $aData->content                 =     $this->getParam('content');

            #逻辑操作
            OtherService::instance()->EditNotice($aData);
            return Redirect::to('/show_notice');}else{
            $id =  $this->getParam('notice_id');
            $info =  OtherService::instance()->GetNoticeInfo($id);
            return $this->view('admin.edit_notice')->with(['notice'=>$info, 'type'=>NoticeEnum::$notice_types]);
        }
    }

    /**
     * 帮助中心列表
     * @author  alice
     * @date    2016-1-18
     * @return mixed
     */
    public function ShowHelpList()
    {
        $info = OtherService::instance()->ShowHelpList();
        return $this->view('admin.show_help')->with('helps',$info);

    }

    /**
     * 帮助中心  添加操作
     * @author  alice
     * @date    2016-1-18
     * @return mixed
     * @throws Exception
     */
    public function AddHelp()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                          =     new stdClass();
            $aData->name                    =     $this->getParam('name');
            $aData->content                 =     $this->getParam('content');

            #逻辑操作
            OtherService::instance()->AddHelp($aData);
            return Redirect::to('/show_help');}else{
            return $this->view('admin.add_help');
        }
    }

    /**
     * 帮助中心  修改操作
     * @author  alice
     * @date    2016-1-18
     * @return mixed
     * @throws Exception
     */
    public function EditHelp()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                          =     new stdClass();
            $aData->id                      =     $this->getParam('id');
            $aData->name                    =     $this->getParam('name');
            $aData->content                 =     $this->getParam('content');

            #逻辑操作
            OtherService::instance()->EditHelp($aData);
            return Redirect::to('/show_help');}else{
            $id = $this->getParam('rec_id');
            $info = OtherService::instance()->GetHelpInfo($id);
            return $this->view('admin.edit_help')->with('help',$info);
        }
    }

    /**
     * 帮助中心  删除操作
     * @author  alice
     * @date    2016-1-18
     */
    public function DeleteHelp()
    {
        #收集信息
        $aData                          =     new stdClass();
        $aData->id                      =     $this->getParam('id');

        #逻辑操作
        OtherService::instance()->DeleteHelp($aData);

    }

    /**
     * 视频列表
     * @author  alice
     * @date    2016-1-19
     * @return mixed
     */
    public function ShowVideoList()
    {
        $info = OtherService::instance()->ShowVideoList();
        return $this->view('admin.show_video')->with('videos',$info);

    }

    /**
     * 添加视频
     * @author  alice
     * @date    2016-1-19
     * @return mixed
     * @throws Exception
     */
    public function AddVideo()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                            =     new stdClass();
            $aData->video_name                =     $this->getParam('video_name');
            $aData->take_time                 =     $this->getParam('take_time');
            $aData->video_url                 =     $this->getParam('video_url');

            #逻辑操作
            OtherService::instance()->AddVideo($aData);
            return Redirect::to('/show_video');}else{
            return $this->view('admin.add_video');
        }
    }

    /**
     * 修改视频
     * @author  alice
     * @date    2016-1-19
     * @return mixed
     */
    public function EditVideo()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $aData                            =     new stdClass();
            $aData->video_name                =     $this->getParam('video_name');
            $aData->take_time                 =     $this->getParam('take_time');
            $aData->video_url                 =     $this->getParam('video_url');

            #逻辑操作
            OtherService::instance()->EditVideo($aData);
            return Redirect::to('/show_video');}else{
            $id = $this->getParam('video_id');
            $info =  OtherService::instance()->ShowVideoInfo($id);
            return $this->view('admin.edit_video')->with('video',$info);
        }
    }



    

}
